#include<stdio.h>

int main (){

       int N;

       scanf("%d",&N);

       while(N--){
               int m,n,d,i;
               scanf("%d %d",&m,&n);

               if(m==1)m=2;

               d = n-m+1;

               bool * a = new bool[d];

               for(i =0;i<d;i++)a[i]=true;
               for( i = m%2;i<d;i+=2)a[i]=false;

               for(i = 3; i*i<=n;i+=2){

                       if(i>=m && !a[i-m])continue;
                       int j = m/i*i;

                       if(j<m)j+=i;
                       if(j==i)j+=i;
                               j-=m;

                       for(;j<d;j+=i){

                       a[j]=false;
                       }
               }

       for(i=m;i<=n;i++){

               if(i==1)a[i-m]=false;
               if(i==2)a[i-m]=true;
               if(a[i-m])printf("%d\n",i);
       }

               if(N)printf("\n");
       }

       return 0;
}